import baseurl from "./config.js"

const userInfo = uni.getStorageSync('userInfo');

const token = userInfo.token // 获取token

// 封装接口方法

function request(obj) {
	let url = baseurl + obj.url;
	let data = obj.data || {};
	let success = obj.success;
	let method = obj.method || 'POST';
	uni.request({
		url: url,
		data: data,
		header: {
			'token': token,
		},
		method: method,
		success: function(res) {
			// 判断token过期时间
			if(res.data.stas == 601) {
				uni.showModal({
					title: '提示',
					content: res.data.statusMsg,
					showCancel: false,
					success: function(res) {
						if(res.confirm) {
							uni.redirectTo({
								url: '/pages/tabbar/login/login.vue'
							})
						}
					}
				})
				 return
			}
			success(res)
		},
		fail: function(res){},
		complete: function(res) {
			console.log()
		}
	})
}
export default {
	request: request,
}
